<template>
	<view class="classlist">
		<view class="loadingLayout" v-if="!classList.length && !noData">
			<uni-load-more status="loading"></uni-load-more>
		</view>
		<view class="content">
			<navigator :url="'/pages/preview/preview?id=' + item._id" class="item" v-for="item in classList" :key="item._id">
				<image :src="item.smallPicurl" mode="aspectFill"></image>
			</navigator>
		</view>
		<view class="loadingLayout" v-if="classList.length || noData">
			<uni-load-more :status="noData?'noMore':'loading'"></uni-load-more>
		</view>
		<view class="safe-area-inset-bottom"></view>
	</view>
</template>

<script setup>
	import {
		apiGetclassList
	} from "@/api/apis.js"

	const classList = ref([])
	const noData = ref(false)
	
	// 定义data参数
	const queryParams = {
		pageNum: 1,
		pageSize: 12
	}
	// 分类方法
	const getClassList = async () => {
		let res = await apiGetclassList(queryParams)
		classList.value = [...classList.value, ...res.data]
		if(queryParams.pageSize > res.data.length) noData.value = true
		uni.setStorageSync('storagClassList',classList.value)
	}

	onLoad((e) => {
		let {
			id = null,
				name = null
		} = e
		queryParams.classid = id
		// 修改导航标题
		uni.setNavigationBarTitle({
			title: name
		})
		// 获取分类列表
		getClassList()
	})

	onReachBottom(() => {
		if(noData.value) return
		queryParams.pageNum++
		getClassList()
	})
</script>

<style scoped lang="scss">
	.classlist {
		.content {
			display: grid;
			grid-template-columns: repeat(3, 1fr);
			gap: 5rpx;
			padding: 5rpx;

			.item {
				height: 400rpx;

				image {
					width: 100%;
					height: 100%;
					display: block;
				}
			}
		}
	}
</style>